package com.lzy.huijinjiazu.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.lzy.huijinjiazu.di.component.DaggerMainComponent;
import com.lzy.huijinjiazu.di.module.MainModule;
import com.lzy.huijinjiazu.mvp.contract.MainContract;
import com.lzy.huijinjiazu.mvp.presenter.MainPresenter;

import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.ui.adapter.TabsAdapter;
import com.lzy.huijinjiazu.mvp.ui.widget.CustomViewPager;


import java.util.ArrayList;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class MainActivity extends BaseActivity<MainPresenter> implements MainContract.View {

    @BindView(R.id.viewPager)
    CustomViewPager mViewPager;
    @BindView(R.id.tabLayout)
    CommonTabLayout mTabLayout;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerMainComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .mainModule(new MainModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_main; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mPresenter.initTabLayout();
    }


    @Override
    public void showTabLayout(ArrayList<CustomTabEntity> tabLayout, Fragment[] fragments) {


        mViewPager.setAdapter(new TabsAdapter(getSupportFragmentManager(), fragments));
        mTabLayout.setTabData(tabLayout);
        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mViewPager.setCurrentItem(position, false);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }
}
